using UnityEngine;
using UnityEngine.UI;

namespace RGuang.PlathformCtrl
{

    public class DefeatScreen : MonoBehaviour
    {
        [SerializeField] VoidEventChannel playerDefeatedEventChannel;
        [SerializeField] AudioClip[] voice;

        [SerializeField] Button btnRetry;
        [SerializeField] Button btnQuit;
        private void OnEnable()
        {
            playerDefeatedEventChannel.AddListener(ShowUI);
            btnQuit.onClick.AddListener(SceneLoader.QuitGame);
            btnRetry.onClick.AddListener(SceneLoader.ReloadScene);
        }
        private void OnDisable()
        {
            playerDefeatedEventChannel.RemoveListener(ShowUI);
            btnQuit.onClick.RemoveListener(SceneLoader.QuitGame);
            btnRetry.onClick.RemoveListener(SceneLoader.ReloadScene);
        }
        void ShowUI()
        {
            GetComponent<Canvas>().enabled = true;
            GetComponent<Animator>().enabled = true;
            SoundEffectPlayer.AudioSource.PlayOneShot(voice[Random.Range(0, voice.Length)]);
            Cursor.lockState = CursorLockMode.None;
        }
    }

}
